I know this is probably very elementary, but I can't seem to figure it out.
I need radio buttons that are mutually exclusive horizontally as well as vertically.
How can I assign a radio button to two groups?
Thanks in advance.
You must set GroupName property in RadioButton.
for example:
<asp:RadioButton ID="rbtnOne" runat="server" Text="One" GroupName="Number" />
<asp:RadioButton ID="rbtnTwo" runat="server" Text="Two" GroupName="Number" />
<asp:RadioButton ID="rbtnMan" runat="server" Text="Man" GroupName="Sex" />
<asp:RadioButton ID="rbtnWoman" runat="server" Text="Woman" GroupName="Sex" />
or use RadioButtonList control
<asp:RadioButtonList ID="rbtnListExample" runat="server">
<asp:ListItem Text="TestOne" />
<asp:ListItem Text="TestTwo" />
<asp:ListItem Text="TestThree" />
</asp:RadioButtonList>
Related
I need to read some value from DB in ASP, I try this code and works fine:
<asp:SqlDataSource ID="SqlDataSource12" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:conexion1 %>"
SelectCommand="select Quantity from XW_ReqLine where ReqNbr=#reqnbr1">
<SelectParameters>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True"
DefaultValue="10124"
Direction="Input"
Name="reqnbr1"
QueryStringField="string"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView15" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource12" AutoGenerateColumns="true"></asp:GridView>
I need to change DefaultValue="10124" to DefaultValue="<%# DataBinder.Eval(Container.DataItem, "ReqNbr") %>" but after that, IIS show an error. The change is because this parameter is not constant
Note: I can't access the code behind (is a comercial software) and only I can made this modifications in the ASP file.
<a4j:outputPanel id="tapalSectionSendToPanel" ajaxsingle="true">
<h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}"
class="createresizedTextbox"
required="true" requiredMessage="#{msg.labl_required}"
disabled="true" />
<h:message for="sendToId1" style="color:red" />
</a4j:outputPanel>
i need to validate textbox for empty validation and should show required when i click button without entering any value in textbox. It works fine without disabled="true". Whats the alternative for my requirement.
First, required and disabled don't go well together, because they are mutually exclusive as per the JSF Spec:
required: Flag indicating that the user is required to provide a submitted value for this input component.
disabled: Flag indicating that this element must never receive focus or be included in a subsequent submit.
Like I said in the comments, you can just display a message when the user tries to submit the form without selecting a node:
<h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}"
styleClass="createresizedTextbox" required="true" readonly="true" />
<h:message for="sendToId1" value="#{msg.labl_required}"
rendered="#{facesContext.postback and facesContext.validationFailed}" />
As an alternative you can just display a text anywhere in your markup:
<h:outputText value="#{msg.labl_required}"
rendered="#{empty MainBean.SectionBean.sendTo}" />
disabled="true" disables the input (so it's skipped when the form is submitted), if you don't want the user to type in it use readonly="readonly"
I have a repeater that is databound to a SqlDataSource
<asp:Repeater runat="server" ID="Repeater" DataSourceID="SqlDataSource">
<ItemTemplate>
<asp:HiddenField runat="server" Value='<%# Eval("Code") %>' ID="Code" />
<asp:TextBox ID="NumberNeeded" runat="server" Text='<%# Eval("Needed") %>' /><br />
</ItemTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="submit" Text="submit" OnClick="submit_Click" />
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="rtvFiltered" SelectCommandType="StoredProcedure">
<SelectParameters>
</SelectParameters>
</asp:SqlDataSource>
I want to iterate over the repeater and get the value in NumberNeeded in submit_Click
protected void submit_Click(object sender, EventArgs e)
{
this.Repeater.DataBind(); //comment this guy and this.Repeater.Items has no items
foreach (RepeaterItem item in this.Repeater.Items)
{
String code = ((HiddenField)item.FindControl("JournalCode")).Value;
// below fails because "NumberNeeded" control doesn't have the Text input by the user.
int numNeeded = Int32.Parse(((TextBox)item.FindControl("NumberNeeded")).Text);
// Doing other stuff with numNeeded
}
}
The repeater displays its items perfectly on the page, but when I click the submit button, this.Repeater.Items is empty (unless I call this.Repeater.DataBind() in that method).
I've tried explicitly data binding Repeater in Page_Load and Page_Init within and outside of a !Page.IsPostBack check, and everytime I either get no Items, or no Text value.
I have gotten an almost identical setup to work in the past, on a page without a master page. I've also noticed that this.Master.EnableViewState is false in the submit_Click method, no matter if I set it to true in Page_Init or Page_Load. this.EnableViewState is true.
As you state, you shouldn't need to call DataBind() in your code behind, so the problem may be with the data retrieval. Does your stored procedure take any parameters? Have you tried adding CancelSelectOnNullParameter="false" to your SqlDataSource?
It was the EnableViewState setting on the master page.
In the Page_Load method of the master page this.EnableViewState was getting set to false. I changed it to Page.EnableViewState and everything worked.
this.EnableViewState = Page.EnableViewState; // add to Master page Page_Load method
do'h
I am working on JSF2.0 and Richfaces. I am having an requirement where I need to change the style of the form field(entire row) if the validation fails. I am using the following code to display field label and text box.
<h:panelGrid columns="2">
<h:outputLabel value="#{uit.firstname}:">
<span class="required"><strong>*</strong> </span>
</h:outputLabel>
<h:inputText value="#{editUserProfileBean.firstName}" type="text"
id="firstname" styleClass="basicFormTextBox" size="30"
required="true" requiredMessage="#{uitkem.valueRequired}"
validatorMessage="#{prod.firstNameValidator}">
<f:validateLength maximum="#{prodConf.MaxLengthForFirstName}"
minimum="#{prodConf.MinLengthForFirstName}" />
<f:validator validatorId="trimSpaces" />
</h:inputText>
</h:panelGrid>
Suppose if the validation fails, I need to hightlight the row(both label and textbox).
I can use the following code to hightlight the textbox if the validation fails. But I want to hightlight the entire row, that is not possible using the following code.
<h:inputText value="#{editUserProfileBean.firstName}" required="true" styleClass="#{not component.valid ? 'newStyleClass' : ''}" />
Can anyone help me on this?
Thanks in advance.
You could just write a tiny JS script with jQuery, or use <rich:jQuery> for that.
I am developing one JSF page, in that i am having two forms. And I am using rich:messages in both the forms.
Suppose, in the first form, if I don't enter any required fields and I click Save, then error messages are displaying twice in the page(as i am using rich:messages in two forms).
Is there any way so that error messages display with respect to the form?
Thanks in advance.
If you are using RichFaces 3.3.3.Final you can do it like so:
<a4j:form id="tmpfrm1">
<rich:messages />
<h:inputText value="#{mybean.intmp1}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test1}" reRender="tmpfrm1" limitToList="true" />
</a4j:form>
<a4j:form id="tmpfrm2">
<rich:messages />
<h:inputText value="#{mybean.intmp2}" required="true"/>
<a4j:commandButton value="save" action="#{mybean.test2}" reRender="tmpfrm2" limitToList="true" />
</a4j:form>
If you are uisng RichFaces 4 you need to replace the limitToList with limitRender and the reRender with render