I have ig:TemplateDataField that contains label.
In InitializeRow event handler I try to find that label with e.Row.FindControl but I get null.
I was not able to find another way to find my label.
How to look for controls in WebDataGrid rows during InitializeRow event?
You have to specify the column that you want to search in like e.Row.Items[0].FindControl("ControlID") where 0 the column index.
Below is a solution that should work.
note: Code is for an Infragistics UltraWebGrid control. The WebDataGrid control is the UltraWebGrid's successor.
C#:
protected void UltraWebGridCustomers_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("HyperLinkEmailColumn").Column;
CellItem cellItem = (CellItem)col.CellItems(e.Row.Index);
HyperLink hyperLinkEmail = (HyperLink)cellItem.FindControl("HyperLinkSendEmail");
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');");
}
VB.NET:
Private Sub UltraWebGridCustomers_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGridCustomers.InitializeRow
Dim col As TemplatedColumn = CType(e.Row.Cells.FromKey("HyperLinkEmailColumn").Column, TemplatedColumn)
Dim cellItem As CellItem = CType(col.CellItems(e.Row.Index), CellItem)
Dim hyperLinkEmail As HyperLink = CType(cellItem.FindControl("HyperLinkSendEmail"), HyperLink)
hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');")
End Sub
Aspx code:
<infragistics:UltraWebGrid ID="UltraWebGridCustomers" runat="server">
<Bands>
<infragistics:UltraGridBand BaseTableName="Customers" Key="BandCustomers">
<Columns>
...
<infragistics:UltraGridColumn Key="NameColumn" BaseColumnName="Name" IsBound="True">
<Header Caption="Name">
</Header>
</infragistics:UltraGridColumn>
<infragistics:UltraGridColumn Key="EmailColumn" BaseColumnName="Email" IsBound="True">
<Header Caption="Email Address">
</Header>
</infragistics:UltraGridColumn>
<infragistics:TemplatedColumn Key="HyperLinkEmailColumn">
<CellTemplate>
<asp:HyperLink ID="HyperLinkSendEmail" NavigateUrl='<%# "~/EmailForm.aspx?email=" & DataBinder.Eval(Container.DataItem,"Email")%>' ToolTip="Send Email" runat="server" />
</CellTemplate>
</infragistics:TemplatedColumn>
...
</Columns>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</infragistics:UltraGridBand>
</Bands>
...
</infragistics:UltraWebGrid>
Related
<p:outputPanel id="panel">
<ui:repeat value="#{dataController.display()}"
var="item" rendered="#{Bean.showtable}">
<b:row>
<b:column col-md="5">
<h:outputText value="#{item.name}" style="font-family: verdana;font-size:16px;margin-bottom:15px;"></h:outputText>
</b:column>
<b:column col-md="7">
<h:inputText style="width:200px;height:30px;margin-bottom:15px;"
autocomplete="off"></h:inputText>
</b:column>
</b:row>
</ui:repeat>
In the above code, I have used ui:repeat for displaying the names of the items in a list in output text alongwith the input text for entering the values of the items.
The input text depends on the values in the list i.e dynamically generated.
I need to access the values from the input text and add them to List.
Can anyone please suggest me an approach to access the values from input text to bean/list despite using ui:repeat once to display the input text?
I have tried to create an empty list and again using ui:repeat only for input text.. tried to access values from input text.But ui:repeat doesnot work again.. as it was already used once for displaying.
I am new to JSF.Any help would be appreciated.Thankyou.
Don't use empty list. Initialize it with null or empty values.
Let's say we have inputs as your list, your bean should look like this.
#Named
#ViewScoped
public class DataController implements Serializable {
private List<String> inputs;
// getters and setters
#PostConstruct
public void init() {
inputs = new ArrayList<String>();
}
public List<Bean> getDisplay() {
List<Bean> display = new ArrayList<Bean>();
// add values to display
for (int i = inputs.size(); i < display.size(); i++) {
inputs.add("");
}
return display;
}
// for testing inputs
public void testInputs() {
for (String input : inputs) {
System.out.println(">>>>>" + input);
}
}
}
xhtml
<ui:repeat value="#{dataController.display()}" varStatus="idx" ...>
...
<h:inputText value="#{dataController.inputs[idx.index]}" style="width:200px;height:30px;margin-bottom:15px;" autocomplete="off"></h:inputText>
...
</ui:repeat>
<p:commandButton value="Test Inputs" action="#{dataController.testInputs}" update="#form" />
Hope this helps.
I have used GetRouteUrl to create SEO friendly URLs but I now want to remove %20 ie spaces and replace with a dash ("-"). An example page from my website is shown below. I want to Title variable to be "madonna-item" and not "Madonna%20Item".
/ProductsByDepartment/Gracya/Madonna/Madonna%20Item?CategoryId=9&productId=8&departmentId=4
I have create a class (StringHelpers) to fix the url but I don't know where to call FixUrl
Public static class StringHelpers
{
public static string FixUrl(this string url)
{
string encodedUrl = (url ?? "").ToLower();
encodedUrl = Regex.Replace(encodedUrl, #"\+", "and");
encodedUrl = encodedUrl.Replace("'", "");
encodedUrl = Regex.Replace(encodedUrl, #"[^a-z0-9]", "-");
return encodedUrl;
}
}
The code which contains the link to update is below. I want to use FixUrl on the Title field, but this does not work.
Please can you advise me how to use FixUrl?
<td class="Product_title" height="20px" width="180px">
<a href='<%#: GetRouteUrl("ProductExtraRoute", new {CategoryId = Eval("catId"), productId = Eval("productId"), departmentId = Eval("depId"), Title = Eval("Title")}).FixUrl()%>' class="Product">
<asp:Literal ID="literal2" runat="server" Text='<%# Eval(("Title").FixUrl()) %>'></asp:Literal>
Try decodeURIComponent
Check this http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp
After this replace all speces with -
The front end (html and css) is set up such a way that for the description text from a Sitecore content field needs to have a <p> tag wrapped around it.
So by default the RTE wraps texts in a <p> tag = TRUE. BUT the catch is you will need to hit Enter or copy/paste multiple paragraphs.
How can we force Sitecore to add a P tag if it's just one line?
Fortunately, From the dll, one particular function caught my eye:
protected virtual void SetupScripts()
{
foreach (XmlNode node in Factory.GetConfigNodes("clientscripts/htmleditor/script"))
this.Result.Scripts.AppendFormat("<script src=\"{0}\" language=\"{1}\"></script>\n", (object) XmlUtil.GetAttribute("src", node), (object) XmlUtil.GetAttribute("language", node));
}
NICE, eh? The developers of SITECORE are clever after all.
So I did this in the web.config,
<!— CLIENT SCRIPTS
These script files are included in the client, e.g. '<script src="/myscript.js" language="JavaScript"/>'
—>
<clientscripts>
<everypage />
<htmleditor>
<script src=”/assets/js/CustomRTE.js” language=”javascript”/>
</htmleditor>
</clientscripts>
And overrode scSendRequest function from EditorWindow.aspx.
window.scSendRequest = function(evt, command) {
var editor = scRichText.getEditor();
if (editor.get_mode() == 2) { //If in HTML edit mode
editor.set_mode(1); //Set mode to Design
}
var htmls = editor.get_html(true);
var regex = /<p[^>]*>.*?<\/p>/i;
var match = regex.exec(htmls);
if(match == null && htmls != null) {
htmls = "<p>" + htmls + "</p>";
}
//$("EditorValue").value = editor.get_html(true);
$("EditorValue").value = htmls;
scForm.browser.clearEvent(evt);
scForm.postRequest("", "", "", command);
return false;
}
AND YAY .. double rainbow and unicorn.
You could create your own custom solution for this requirement as well.
You could create a new pipeline event in the
<saveRichTextContent> pipeline - This could enable you to append the tag when you hit save on the rich text editor in sitecore
<renderField> pipeline - This could on the fly wrap your text into <p></p> tags while rendering the page, if the tag was not there in the original rtf text.
If you go for method 1: <saveRichTextContent>
You could add to the pipeline in web.config:
<processor type="Sitecore72.Classes.WrapRichTextInParagraphOnSave, Sitecore72" />
And you could use the following corresponding code:
namespace Sitecore72.Classes
{
public class WrapRichTextInParagraphOnSave
{
public void Process(SaveRichTextContentArgs args)
{
if (!(args.Content.Trim().StartsWith("<p>") && args.Content.Trim().EndsWith("</p>")))
args.Content = "<p>" + args.Content + "</p>";
}
}
}
Please note, that this pipeline gets triggered only when you use the Show Editor buttong of a rich text field:
If you go for method 2: <renderField>
To append to this pipeline you would use this config:
<processor type="Sitecore72.Classes.WrapRichTextInParagraphOnRender, Sitecore72" />
And you could use the following corresponding code:
namespace Sitecore72.Classes
{
public class WrapRichTextInParagraphOnRender
{
public void Process(RenderFieldArgs args)
{
if (args.FieldTypeKey == "rich text" && !(args.Result.FirstPart.Trim().StartsWith("<p>") && args.Result.FirstPart.Trim().EndsWith("</p>")))
args.Result.FirstPart = "<p>" + args.Result.FirstPart + "</p>";
}
}
}
For both these, ensure you add reference to Sitecore.Kernel.dll and HtmlAgilityPack.dll. Both of these are available with the sitecore package solution.
This question already has answers here:
Showing Hibernate/JPA results in JSF datatable causes: java.lang.NumberFormatException: For input string: "[propertyname]"
(2 answers)
Closed 6 years ago.
I'm trying to replicate this guide but with jsf 2.2:
http://www.mkyong.com/jsf2/jsf-2-datatable-example/
My current setup: a class called Message holds a date, string, and an account object called "name" (its owner). A MessageBean class has a List object messageSet, that gets initialized in the MessageBean constructor. A JSF page fills a table with the messageList. However, the table doesn't get filled. When looking at the list object in the debugger, it does get filled with valid message objects. My classes:
#Named(value = "messageBean")
#SessionScoped
public class MessageBean implements Serializable
{
private List messageSet;
public MessageBean()
{
this.messageSet = Controller.Controller.getLatestKweks();
}
public List<Message> getMessageSet()
{
return messageSet;
}
public void setMessageSet(List<Message> messageSet)
{
this.messageSet = messageSet;
}
}
The JSF page:
<h:dataTable value="#{messageBean.messageSet}" var="mes">
<h:column>
<f:facet name="header">Date</f:facet>
#{mes.mesDate}
</h:column>
<h:column>
<f:facet name="header">Naam</f:facet>
#{mes.name.accountName}
</h:column>
<h:column>
<f:facet name="header">Content</f:facet>
#{mes.Content}
</h:column>
</h:dataTable>
There's a second Message object that is a Hibernate object, only having getters and setters in it.
Here's the stacktrace when I try to access this page:
java.lang.NumberFormatException: For input string: "mesDate"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:378)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:198)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.TableRenderer.renderRow(TableRenderer.java:385)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:162)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:724)
THe component tree:
<UIViewRoot id="j_id1" inView="true" locale="en_GB" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/hoofdpagina.xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<UIOutput id="j_idt2" inView="true" rendered="true" transient="false">
<title>Main page</title>
</UIOutput>
<UIOutput id="j_idt4" inView="true" rendered="true" transient="false">
<div id="menu">top</div> <div id="currentMessages">
<HtmlDataTable border="-2147483648" first="0" id="j_idt6" inView="true" rendered="true" rowIndex="0" rowStatePreserved="false" rows="0" transient="false" var="mes">
<UIColumn header="Datum" id="j_idt7" inView="true" rendered="true" transient="false">
header
Date
#{mes.mesDate}
</UIColumn>
<UIColumn header="Name" id="j_idt10" inView="true" rendered="true" transient="false">
header
Name
#{mes.name.accountName}
</UIColumn>
<UIColumn header="Inhoud" id="j_idt13" inView="true" rendered="true" transient="false">
header
Content
#{mes.mesContent}
</UIColumn>
</HtmlDataTable>
</div>
</UIOutput>
</html>
</UIViewRoot>
And the scoped variables:
Name Value
j_idt6 j_idt6
j_idt6:j_idt10 bread
j_idt6:j_idt12 Log in
j_idt6:j_idt8 Donald
AttributesName Value
None
Request AttributesName Value
kwek [Ljava.lang.Object;#a5c775c
Flash AttributesName Value
None
Session AttributesName Value
None
Application AttributesName Value
csfcff [ ]
Anyone have any idea why the table won't fill?
Your Hibernate/JPA query is broken. The code behind getLatestKweks() is actually returning a List<Object[]>, not List<Message>.
Evidence is in the stack trace:
java.lang.NumberFormatException: For input string: "mesDate"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:378)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:198)
...
The ArrayELResolver is only involved when the base of mesDate (thus, the #{mes}) represents an array like Object[] not a javabean like Message. EL is attempting to use the mesDate to obtain the array item by index, which can only be an integer like so #{mes[0]} for the 1st item. However, the string value "mesDate" is not parseable as an integer and hence this exception.
You have 2 options to solve this problem:
Alter the code to expect a List<Object[]>. Use e.g. #{mes[0]}, #{mes[1]}, etc.
Fix the Hibernate/JPA query to return a real List<Message>. Specify Message.class as type.
See also:
NumberFormatException for input String
EDIT: I added in the hf from the first reply that was pointed out. This helped with a few other issues, but still did not fix the problem.
I am trying to bind a list to a gridview with a LOT of hidden fields (I'll only use 2 of the 50) for temporary holding so the user can create and delete multiple items without going back and forth to the database multiple times during creation. I'm fine with binding to and recalling from the BoundFields; however, when I try to recall the hidden field values it comes back as null. I may be having problems with the binding to the hidden fields. Here's my code
ASP:
<asp:GridView ID="grdOtherCarrier" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Sequence" DataField="Sequence"></asp:BoundField>
<asp:BoundField HeaderText="Pay ID" DataField="PayID"></asp:BoundField>
<asp:BoundField HeaderText="Provider" DataField="Provider"></asp:BoundField>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:HiddenField ID="hfInsuredLastName" Value="<%#Eval("InsuredLastName")%>" runat="server" />
<asp:HiddenField ID="hfInsuredFirstName" Value="<%#Eval("InsuredFirstName")%>" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C# / code behind:
protected void lblSubmitOtherCarrier_Click(object sender, EventArgs e)
{
List<OtherCarrier> OCList = new List<OtherCarrier>();
OtherCarrier OC;
foreach (GridViewRow row in grdOtherCarrier.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
OC = new OtherCarrier();
String Sequence = row.Cells[0].Text.ToString() ; // primary value
String PayID = row.Cells[1].Text.ToString(); // primary value
String Provider = row.Cells[2].Text.ToString(); // primary value
HiddenField InsuredLastName = (HiddenField)row.FindControl("hfInsuredLastName");
HiddenField InsuredFirstName = (HiddenField)row.FindControl("hfInsuredFirstName");
OC.Sequence = Sequence;
OC.PayID = PayID;
OC.Provider = Provider;
OC.InsuredLastname = InsuredLastName.Value.ToString();
OC.InsuredFirstName = InsuredFirstName.Value.ToString();
OCList.Add(OC);
}
}
OC = new OtherCarrier();
OC.Sequence = txtSequence.Text;
OC.PayID = txtPayID.Text;
OC.Provider = txtProvider.Text;
OC.InsuredLastname = txtInsuredLastname.Text;
OC.InsuredFirstName = txtInsuredFirstName.Text;
OCList.Add(OC);
TD.OtherCarrierList = OCList;
grdOtherCarrier.DataSource = OCList;
grdOtherCarrier.DataBind();
mpeAddOtherCarrier.Hide();
txtSequenceNo.Text = (grdOtherCarrier.Rows.Count + 1).ToString();
}
When it gets to assigning the OC.InsuredLastname from the hidden field the hidden field is coming up as null value. Either I'm not reading it correctly or it's not being written correctly.
so...
you are trying to find a control as
(HiddenField)row.FindControl("InsuredLastName");
as you can see, named InsuredLastName when you explicit say in the HTML that your control name is:
<asp:HiddenField
ID="hfInsuredLastName"
Value="<%#Eval("InsuredLastName")%>"
runat="server" />
named hfInsuredLastName
all you need to do is change the call to
(HiddenField)row.FindControl("hfInsuredLastName")