Tiles - Spring MVC - spring-mvc

What is the difference between
<tiles:useAttribute ...>
and
<tiles:insertAttribute ...>
Can you give some example?

See http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/insertAttribute.html and http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/useAttribute.html.
useAttribute declares a variable containing the attribute. insertAttribute inserts the attribute in the response. It's basically the same difference as there is between
String id = attributeValue("theAttribute");
and
out.println(attributeValue("theAttribute"));

Thanks #JB Nizet!
Actually i needed this tile attribute to be used in jsp page. I have found the difference and its almost same thing that you explained. However, I would like to share my example to those who are trying it on jsp page
code snippet of myLayout.jsp
<tiles:useAttribute name="my_title"/>
<c:if test="${not empty my_title}">
<tiles:insertAttribute name="my_title"/>
</c:if>
useAttribute will in some sense convert "my_title" into a variable which now can be manipulate as a normal jsp variable. This new variable will carry the value provided by tiles definition. Hence, the variable can be checked if its empty or blank and if it is not empty, the value is outputed to the browser(response) by using insertAttribute
Here is the sample tile definition:
<definition name="test" template="myLayout.jsp">
<put-attribute name="my_title" value="Web Blog" />
</definition>
enjoy!

Related

Asp.net textbox shows text and value differently

I am populating the value of a text box using javascript document getElementById.
I am able to see the text change in UI. However in code behind it shows a different value. I did inspect element on the input and saw the value and text are showing differently. How is this possible.
This is what I see on inspect element Value = '19 Bradston Street (South Bay)' but the UI shows ' 35-49 East Santa Clara Street' :-
<input name="ctl00$ContentPlaceHolder1$CtlPropertySales$txtBuildingName" type="text" value=" 19 Bradston Street (South Bay)" id="ctl00_ContentPlaceHolder1_CtlPropertySales_txtBuildingName" tabindex="95" style="font-family:tahoma,verdana;font-size:11px;font-weight:normal;height:16px;width:150px;">
This is the Javascript code that is setting the value:-
document.getElementById('<%=CtlPropertySales.FindControl("txtBuildingName").ClientID%>').value = params[1]
Can any one tell me how this is possible and how I can solve this.
It looks like you might not be getting the ID properly. You're looking for
<%=CtlPropertySales.FindControl("txtBuildingName").ClientID%>
but what is the ID for CtlPropertySales? Try getting the ClientID of CtlPropertySales first, then get the ClientID of txtBuildingName.
Or just
document.getElementById('<%=ctl00_ContentPlaceHolder1_CtlPropertySales_txtBuildingName.ClientID%>').value= params[1]
You might consider add this to your web.config:
<system.web>
<pages clientIDMode="Static">
</system.web>
With clientIDMode="Static", IDs will retain their original name and you will not need to use ctl00 or ClientID any more. That should help with setting values, but it will affect all the IDs in the app/site and you'll have to update scripts.

Set Spring Webflow attribute dynamically

I would like to set an attribute dynamically on a view-state like:
<view-state id="any" view="/some.view.xml">
<attribute name="attr" value="#{true ? 'a' : 'b'}"/>
</view-state>
but the value is just taken as plain text. What ways do I have to change 'attr' based on a value in my model.
Explanation
The tag will not work since it only supports plain strings, not EL expressions.
I found a solution by adding info to the variable temp in an action call and evaluating it in the flow with
<on-entry><set name="viewScope.attr" value="flowScope.temp eq 'X' ? 'aaaa' : 'bbbb'" /></on-entry>

How can I write raw XML to a Label in ASP.NET

I am getting a block of XML back from a web service. The client wants to see this raw XML in a label on the page. When I try this:
lblXmlReturned.Text = returnedXml;
only the text gets displayed, without any of the XML tags. I need to include everything that gets returned from the web service.
This is a trimmed down sample of the XML being returned:
<Result Matches="1">
<VehicleData>
<Make>Volkswagen</Make>
<UK_History>false</UK_History>
</VehicleData>
<ABI>
<ABI_Code></ABI_Code>
<Advisory_Insurance_Group></Advisory_Insurance_Group>
</ABI>
<Risk_Indicators>
<Change_In_Colour>false</Change_In_Colour>
</Risk_Indicators>
<Valuation>
<Value xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></Value>
</Valuation>
<NCAP>
<Pre_2009></Pre_2009>
</NCAP>
</Result>
What can I do to make this appear on the screen? I noticed that Stack Overflow does a pretty good job of putting the XML on the scren. I checked the source and it's using <pre> tags. Is this something that I have have to use?
It would be easier to use a <asp:Literal /> with it's Mode set to Encode than to deal with manually encoding Label's Text
<asp:Literal runat="server" ID="Literal1" Mode="Encode" />
You need to HtmlEncode the XML first (which escapes special characters like < and > ):
string encodedXml = HttpUtility.HtmlEncode(xml);
Label1.Text = encodedXml;
Surrounding it in PRE tags would help preserve formatting, so you could do:
string encodedXml = String.Format("<pre>{0}</pre>", HttpUtility.HtmlEncode(xml));
Label1.Text = encodedXml;
As Bala R mentions, you could just use a Literal control with Mode="Encode" as this automatically HtmlEncodes any string. However, this would also encode any PRE tags you added into the string, which you wouldn't want. You could also use white-space:pre in CSS which should do the same thing as the PRE tag, I think.

spring webflow: redirect in end-state depending on some input

I have in my flow some input, i.e.
<input name="someInput" type="long" required="true"/>
and I'd like to redirect in an end-state to a location that depends on this input. I'm trying the following:
<end-state id="done" view="externalRedirect:contextRelative:/blahblah/${someInput}"/>
This is not working (the webflow does not replace ${someInput} with its value (it treats this as a standard string. Do you know how to do this properly?
If you are speaking about Webflow 2.0 please try
<end-state id="done" view="externalRedirect:contextRelative:/blahblah/#{someInput}"/>

Handling Arrays of HTML Input Elements with Request.Form Like PHP

How can I properly receive these Array of Inputs on asp.net?
<input type=hidden name='field[name][]' value='alex' />
<input type=hidden name='field[name][]' value='mark' />
<input type=hidden name='field[name][]' value='helen' />
<input type=hidden name='field[age][]' value='22' />
<input type=hidden name='field[age][]' value='30' />
<input type=hidden name='field[age][]' value='29' />
In php you can access field by $field = $_POST["field"]
$field["name"] and $field["age"] are simply arrays containing names and ages.
actually, it does exist with asp.net. - you can use
string[] MyTest = Request.Form.GetValues("MyTest");
or
string[] MyTest = Request.QueryString.GetValues("MyTest");
You can use a standard string split - this is all php does for you behind the scenes. PHP is not a strongly typed language however which means that it is a LOT easier for them to provide the "appearance" of this functionality.
The reality is that php is just allowing you to provide comma delimited input and it automatically splits it for you.
So... if you want to do this in asp.net, you can use the same input name a number of times and it will be returned with the request object as a comma delimited list. I would not recommend using this approach for user entered input, but it will work fine if you are contrrolling the input like combining a list into a hidden input from a jquery script.
To get your head around what is happening (with php too.. all web dev techs are using the same http rules), just try posting a form with an input (don't set runat server) that is there twice.
<input type="text" name="MyTest" value="MyVal1" />
<input type="text" name="MyTest" value="MyVal2" />
On pageload add this
if(IsPostBack)
{
Response.Write(Request["MyTest"]);
}
You should see
MyVal1,MyVal2
On the screen.
Now, if you want this into an array, you can:
string[] myvals = Request["MyTest"].Split(',');
if you want Integers or other datatypes (php doesn't know/care what a datatype is really), you will have to loop through it and parse it into another array/generic list.
I don't know what your wanting as an end result, but understanding what the browser posts back is the first step and the short answer is...
Yes, ASP.NET can do this to (just a little more manually).
These are not arrays of inputs. HTML doesn't have a concept of arrays.
These are simply groups of inputs with the same name.
What are you trying to achieve? Why are you not using server side controls?
Update:
You can access the Request.Forms collection - it will hold the posted form elements.
Alternatively, use server side controls - you will be able to access these by ID.

Resources