How to set <s:property> value to Struts 2 Checkbox in Iterator and give all the selected check boxes value in Action List - html

I Want to get selected checkbox value from checkbox Key property on Action Class as List.
My code look like this
<s:form action="SearchEmail">
<s:iterator value="ls">
<s:checkbox name="chk" key="number" />
</s:iterator>
<s:submit value="Go"/>
</s:form>
<s:iterator value="ls" status="stat">
<s:checkbox name="chk[%{#stat.index}]" key="number" />
<%-- <s:property value="number"/> --%>
</s:iterator>
The output is:
Value of CheckBox:{0=true, 1=false, 2=true}
But I need value in String format I don't need Index I need Value of Key property of Checkbox. I want to get the value of Selected Property.

<s:property value="number"/>
<s:checkbox fieldValue="%{number}" name="chk" key="number"> </s:checkbox> <!-- key="number" -->
</s:iterator>
wow it's working with above code.Something Magic. Thank every one to letting me resolve it on my own.

here 'var' attribute makes the sense
<s:iterator value="ls" var="val">
<s:checkbox name="%{val}" id="%{val}" label="%{val}"></s:checkbox>
</s:iterator>

Related

What is the difference with brackets [] and without them in Angular HTML?

I used reactive form in angular and put radio-button to my HTML code.
First I put code like below and used 'default' key word to on check box select default. But I second load same form default check not visible. In type script form ,I will patch value 'true' to form controller as default.
<mat-radio-button value="true" id="1" [checked]="true" />
<mat-radio-button value="false" id="2" />
After I changed it like below.
<mat-radio-button [value]="true" id="1" />
<mat-radio-button [value]="false" id="2" />
now it worked as expected. Need some expert help to , what happen this different way in internally ?
Brackets tells Angular that input bound property is an expression and needs to be evaluated. Eg this:
<mat-radio-button [prop]="prop" />
Will try to access a prop variable on its scope and get its value, while
<mat-radio-button prop="prop" />
will simply add prop attribute to the element with a string value assigned
value="true" bind the string 'true' instead of a boolean value.
[value]="true" bind to the boolean true. With bracket [], Angular bind to a literal (boolean, string, number, etc.) or to anything from your component that is public or to template variable.
value="true" is the same as [value]="'true'".

JSF onclick radio button hide/show textbox

I want to implement functionality like, when I'm selecting one radio button it has to show one text box otherwise it should be in the hidden state. I wrote code like this
<tr>
<th><label for="selection">Register as ::</label></th>
<td> <h:selectOneRadio id="selection" value="#{LoginBean.role}" label="Action" required="true">
<f:selectItem itemValue="Customer" itemLabel="Customer" />
<f:selectItem itemValue="Manager" itemLabel="Manager" />
<p:ajax process="console" update="#form" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<th><h:outputLabel value="Enter your Fee ::" rendered="#{LoginBean.role eq 'Manager'}"></h:outputLabel></th>
<td><h:inputText id="fee" value="#{LoginBean.fee}" rendered="#{LoginBean.role eq 'Manager'}" required="true" requiredMessage="Fee is required." class="form-control" a:placeholder="200.00" ></h:inputText></td>
</tr>
Here, If I select Manager radio button it should show the outputLabel and inputeText.
There are getter and setters in the Bean Class.
Is there anything wrong?
instead of the input row as in your code,
I would recommend you put it in another form with rendered="#{LoginBean.isManager }", take out both rendered in your h tag.
Duplicate this form without any child tag, this form comes with rendered="#{!LoginBean.isManager }"
In your Bean, declare new boolean isManager with getter setter.
As you process your radio choice form, Bean will set isManager to false or true based on your choice and render the form according to your isManager.
I used this way to quick add "Edit" form. It works without POSTBACK. I hope it works for you!
PS: You may only need to set rendered to tr tag instead of h tag.

Struts2 checkbox tree structure?

I need to make a tree structure with my JSP Code.
In the data taken from a database, there's a parent field which should identify the child nodes; I use the
<s:iterator value="Activities">
<s:property value="idActivity" />
<s:property value="name" />
<s:property value="parent" />
</s:iterator>
Any ideas? I tried to use dynatree Library from GoogleCode but it didn't work.
If by tree structure you mean a tree-like indentation, just use <ul> and <li>.
Also pay attention to the list you're iterating, that should start with a lowercase letter:
<ul>
<s:iterator value="activities">
<li>
<s:property value="idActivity" />
<s:property value="name" />
<s:property value="parent" />
</li>
</s:iterator>
</ul>
BTW the question is very unclear, and it doesn't involve any checkbox. Try to be more specific next time (or this one, if this answer is not the one you're looking for)

Why jsf <h:inputHidden../> is taking space on the screen?

Among most primefaces component on my screen, I happen to have used an h:inputHidden on my xhtml page as I needed a hidden field to store/update a bean field value.
<h:inputHidden id="calendarValueHidden" value="#{myCdiBean.calValue}"/>
Even though it is not visible, but I don't know why it is taking space on the screen which has disturbed other components of the page. Even display:none !important is not working on the input hidden component.
The problem symptoms indicate a common starter's mistake: declaring it as an immediate child of a <h:panelGrid>. Like so:
<h:panelGrid columns="1">
<h:inputText ... />
<h:inputText ... />
<h:inputHidden ... />
<h:inputText ... />
</h:panelGrid>
The <h:panelGrid> generates a HTML <table> and, as documented, it will put every direct child in its own table cell <td>. The generated HTML output looks like this:
<table>
<tbody>
<tr><td><input type="text" /></td></tr>
<tr><td><input type="text" /></td></tr>
<tr><td><input type="hidden" /></td></tr>
<tr><td><input type="text" /></td></tr>
</tbody>
</table>
A <td> has by default some margin and padding which totally explains your problem. You should have noticed it when inspecting the HTML output and CSS styles in browser's builtin developer toolset (press F12 or rightclick, Inspect Element).
You basically want to group the <h:inputHidden> along with the desired <h:inputText> inside the same table cell. You can use <h:panelGroup> for that.
<h:panelGrid columns="1">
<h:inputText ... />
<h:panelGroup>
<h:inputText ... />
<h:inputHidden ... />
</h:panelGroup>
<h:inputText ... />
</h:panelGrid>
This will end up in the generated HTML output as below, exactly as you intented:
<table>
<tbody>
<tr><td><input type="text" /></td></tr>
<tr><td><input type="text" /><input type="hidden" /></td></tr>
<tr><td><input type="text" /></td></tr>
</tbody>
</table>
Unrelated to the concrete problem, using tables for layout and positioning is bad. Use divs and CSS.
The problem is, I placed the hidden field inside the panel grid, just after the component, the value of which it holds. I took it out of the panel grid and placed it in the end just before the end of the form tag. Problem solved.
Looks like a panel grid does not take a hidden field for actually a literally non-present component. It is still counted by a panel grid because it is still in dom. For an element to be an uncountable element in panel grid, it has to be unrendered (rendered="false"). But then it also becomes totally inaccessible and its value wont be available as it is no more in dom.

How to arrange two buttons side by side in Struts2

I am developing a Web page on struts2 If I am correct theme in Struts2 is set such that all the tags will eventually be inside a table so all tags will be aligned one below other.
In My web page i have login page with Submit and Reset button I want both side by side (next each other) rather than in separate line.I Tried googling i got some answer like { display : inline; } in CSS and also { position : float} and theme="simple" in form. Nothing worked
<table><tr><td><s:submit method="CheckUser" value="Login" align="center" /></td><td><s:reset value="Clear" align="center" /></td></tr>
In case if i set i get the 2 buttons(submit+reset) as required
but though label="User Id" is given i get only text field without label
<tr><td><s:textfield name="userid" label="User Id" size="25" /></td></tr>
<tr><td><s:password name="password" label="Password" size="25" /></td></tr>
Please do suggest me where I am going wrong and how to get both label to text field and also submit_Reset button side by side
Just leave default Struts2 theme, which is xhtml by the way, as it is and change only your <s:submit> and <s:reset> tags adding to them theme attribute with value simple.
<s:form>
...
<tr>
<td colspan="2">
<s:submit value="Login" theme="simple"/>
<s:reset value="Clear" theme="simple"/>
</td>
</tr>
</s:form>
In struts.xml set the theme to simple
<struts>
...
<constant name="struts.ui.theme" value="simple" />
...
<struts>
Now things will work as you expect.
The theme can also be scoped in other ways if you don't want the simple to to be default (page and per tag are common) see here: http://struts.apache.org/2.3.8/docs/selecting-themes.html