<h:selectManyCheckbox> binding solution - java

i have one component as below,which is binded by HtmlSelectManyCheckbox,
<h:selectManyCheckbox id="chk_weekdays"
onclick="restrictCheck(this)"
binding="#{Holiday_Declaration.chk_weekedays}"
>
<f:selectItem id="chk_1" itemLabel="Monday" itemValue="1" />
<f:selectItem id="chk_2" itemLabel="Tuesday" itemValue="2" />
<f:selectItem id="chk_3" itemLabel="Wednesday" itemValue="3" />
<f:selectItem id="chk_4" itemLabel="Thursday" itemValue="4" />
<f:selectItem id="chk_5" itemLabel="Friday" itemValue="5" />
<f:selectItem id="chk_6" itemLabel="Saturday" itemValue="6" />
<f:selectItem id="chk_0" itemLabel="Sunday" itemValue="0" /></h:selectManyCheckbox>
and i want total number of checked checkboxes and their values using backing bean Holiday_Declaration.
Thanks for any help...

Have following field in your managed bean
private List<String> chk_weekedays;
// getters/setters
Cover your component in an h:form and on submit access this list from some action

Related

primefaces selectonemenu ajax listener not working in Dialog Box

I am trying to retrieve the value of Dropdown/selectonemenu, which is in Dialog.
But not getting it using listener/valueChangeListener.
My xhtml code:
<p:selectOneMenu id="test" value="#{report.location}" style="width:13% !important;">
<p:ajax listener="#{report.locationChange}" />
<f:selectItem itemLabel="All" itemValue="All" />
<f:selectItem itemLabel="INSHOP" itemValue="INSHOP" />
<f:selectItem itemLabel="INSTORAGE" itemValue="INSTORAGE" />
</p:selectOneMenu>
My Java code for listener to print the value for location:
public void locationChange() {
//location = (String) ((UIOutput) event.getSource()).getValue();
System.out.println("Location :: "+location);
}
Its not printing the location, just giving me NULL.
But when i am trying the same thing outside the DIALOG box, its showing the correct result.
Try using valueChangeListener="#{report.locationChange}" in p:selectOneMenu instead of p:ajax
<h:selectOneMenu value="#{qbaggageModel.deliveryAddrType}">
<f:selectItem itemLabel="Select" itemValue=""> </f:selectItem>
<f:selectItem itemLabel="Permanent" itemValue="Perm"> </f:selectItem>
<f:selectItem itemLabel="Temporary" itemValue="Temp"> </f:selectItem>
<f:ajax execute="#form" render="delDtlsDiv" listener="#{qbaggageHandler.copyAddress}" />
</h:selectOneMenu>
Note : This code should be enclosed in a <h:form></h:form>

To read JSF commandbutton action attribute value through javascript

Hi is there any way through which i can read JSF command button action attribute value.My command button statement is
<h:commandButton id="cmdBtn" value="GO" action="#{managedBean.submit}"onclick="javascriptfunction()"/>
action attribute is getting value from managed bean and command button is within a form.
below is my select menu
<h:selectOneMenu id="workspaceOptions"
value="#{workSpaceBean.selectedItem}" class="selectMenu">
<f:selectItem id="header" itemLabel="Select" itemValue="#{null}" />
<f:selectItem id="option1" itemLabel="Assignments" itemValue="assignment" />
<f:selectItem id="option2" itemLabel="Preview" itemValue="preview" />
<f:selectItem id="option3" itemLabel="Edit Coverage" itemValue="editCoverage" />
<f:selectItem id="option4" itemLabel="attachment" itemValue="attachment" />
</h:selectOneMenu>
<h:commandButton id="cmdBtn" value="GO" class="commandButton"
action="#{workSpaceBean.submit}" onclick="javascriptfunction()" />`
For the options editCoverage,attachment i would be getting multiple outcomes based on some conditions in the managed bean.All i want to do is open the outcome views of these in new window and for remaining options need to remain in same page.

How do i hide the f:selectItem tag under h:selectOneRadio

For <f:selectItem> there is no rendered attribute. How can I hide a particular <f:selectItem> under <h:selectOneRadio>?
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" value="#{}" rendered="#{}">
<f:selectItem itemValue="ALL" itemLabel="#{ONE}" />
<f:selectItem itemValue="PRIVATE" itemLabel="#{TWO}" />
<f:selectItem itemValue="GROUP" itemLabel="#{THREE}" />
</h:selectOneRadio>
In above code I want to hide the second item.
The <f:selectItem> is a tag handler (which evaluated during view build time), not a JSF component (which is evaluated during view render time). You can only show/hide it with another tag handler, such as JSTL <c:if>.
<h:selectOneRadio value="#{bean.selectedItem}">
<f:selectItem itemValue="ALL" itemLabel="#{ONE}" />
<c:if test="#{!bean.showPrivate}">
<f:selectItem itemValue="PRIVATE" itemLabel="#{TWO}" />
</c:if>
<f:selectItem itemValue="GROUP" itemLabel="#{THREE}" />
</h:selectOneRadio>
Only when #{bean} is been prepared during view render time by an iterating JSF component such as <h:dataTable> or <ui:repeat> then the above won't work and you really have to do it in the backing bean code instead.
You can use f:selectItems .
For example:
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" rendered="true" value="controller.value">
<f:selectItems value="#{controller.items}" />
</h:selectOneRadio >
This is class controller:
public clss Controller(){
private List<SelectItem> items = new ArrayList<SelectItem>();
public Collection<SelectItem> getItems(){
if (items.isEmpty()){
createItems();
}
return this.items;
}
public private createItems(){
if (condition){ //Here you can hidden the selectItem
this.items.add(new SelectItem(value,label));
}
}
}
you can try to surround it in
<h:panelGrid rendered="">
h:selectOneRadio
</h:panelGrid >
EDITED:
or use
<h:panelGroup>
Edit
its not good idea but i think you can do it by code redundancy as follow
<h:panelGroup rendered="#{}">
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" rendered="true">
<f:selectItem itemValue="ALL" itemLabel="one" />
<f:selectItem itemValue="PRIVATE" itemLabel="two" />
<f:selectItem itemValue="GROUP" itemLabel="THREE" />
</h:selectOneRadio>
</h:panelGroup>
<h:panelGroup rendered="#{!}">
<h:selectOneRadio id="radio11" styleClass="selectOneRadio" rendered="true">
<f:selectItem itemValue="ALL" itemLabel="one" />
<f:selectItem itemValue="PRIVATE" itemLabel="two" />
</h:selectOneRadio>
</h:panelGroup>
I am not able to understand the markup/source, but guessing from the heading, I will suggest
$("a.selectOneRadio f.selectItem").hide()
should do the job assuming
1) selectOneRadio is the class name of the a tag.
2) selectItem is the class name of the f tag.
3) f is not a tag in HTML. So if `f` is also a class name, you would have to use `.f .selectItem`
If you can please provide some details in the question.
There is also a disabled property on f:selectItem elements, if that fulfills your needs. Otherwise you will have to add them manually as Michel Foucault suggested.

<t:selectOneRadio link to backbean problem

I have used Tomahawk <t:selectOneRadio> in my jsf page. I have reserved one boolean value for each radio button in my back bean, but I have a problem with linking the component to the backing bean. How must I link the component to the backing bean?
Is my data model in backing bean wrong?
This is my code:
<t:radio index="0" for="select"></t:radio>
<t:selectOneRadio id="select" layout="spread">
<f:selectItem itemLabel="Every" itemValue="Every" />
<h:inputText id="days" /> days
<br />
<t:radio index="1" for="select"></t:radio>
<f:selectItem itemLabel="Every Weekday"
itemValue="Every Weekday" />
</t:selectOneRadio>
Use the value attribute.
<t:selectOneRadio value="#{bean.selectedItem}">
That said, the component is not used the correct way in your code. Only the selectitems should go in the component and the t:radio index should start with 0. Here's a rewrite:
<t:selectOneRadio id="frequency" value="#{bean.frequency}" layout="spread">
<f:selectItem itemLabel="Every" itemValue="Every" />
<f:selectItem itemLabel="Every weekday" itemValue="Every weekday" />
</t:selectOneRadio>
<t:radio for="frequency" index="0" /><h:inputText value="#{bean.days}" /> days
<br />
<t:radio for="frequency" index="1" />
In the bean you need the following:
private String frequency;
private Integer days;
// Add/generate getters and setters.
Depending on the selection, the selected itemValue will be set as frequency (which can thus be either "Every" or "Every weekday") and the entered days will be set as days.

JSF: how to rendered=#{bean.isRendered} multiple components at one time

I tried this but does not work:
<f:verbatim rendered="#{bean.isRendered}">
<h:selectOneMenu>
...
</h:selectOneMenu>
<h:selectOneMenu>
...
</h:selectOneMenu>
<h:selectOneMenu>
...
</h:selectOneMenu>
</f:verbatim>
I can put the rendered attributes inside each <h:selectOneMenu>, ohh well :D it would be easier if I group them like above
<h:panelGroup rendered="#{bean.someBoolean}">
<!-- multiple elements here -->
</h:panelGroup>

Categories

Resources