Using Sitebricks, I want to generate a table where one object backs each <td> in a table. The only examples I've seen have one object back an entire <tr> - so the HTML is consistent across each row. I would like to be able to wrap N entries in <tr>.
I don't want to have to have my page object in Sitebricks be aware of the layout of the page (and so have to add indices or structure the items as a List<List<Something>>).
Any ideas?
Edit: This is, of course, not limited to Sitebricks, but is a general question about separation of model from view using web templating systems.
Yep, you can add #Repeat on any tag. The implicit variables index and last are defined for you to do your own logic inside the repeat. You could, for example, add a CSS class if index % 2 == 0 to color even rows differently.
Here is a testcase showing how this works for non-table tags (the tags really don't matter):
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
Seems like you can put the #Repeat in front of anything. I don't think it cares about whether it's a row in a table or a column.
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
If you're trying to keep track of the index so you can emit special stuff every nth row, I don't know.
Related
I am preparing to embark on a large solo project at my place of employment. First let me describe the project. I have been asked to create a Java program that can take a CamT54 file (which is just a xml file) and have java display the information in table form. Then users should be given the ability to remove certain components from the table and have it go back to xml format with the changes.
I'm not well versed in dealing with XML in Java so this is going to be a learn and work task. Before I begin investing time I would like to know that my approach is the best approach.
My plan is to use DOM4J to do the parsing and handling of the xml. I will use a JTable to display the data and incorporate some buttons to the GUI that allow the modifications of the data through the use of some action listeners.
Would this be a plausible plan? Can DOM4J effectively allow xml data to be displayed in a table format and furthermore could that data be easily modified or deleted then resaved to a new xml?
I thought I would go ahead and answer this as I finished the program and wanted to post what I thought was the easiest solution in case anyone else needed help.
It turned out the easiest approach (for me at least) was to use the standard DOM parser, here are the steps I took.
Parsed the entire XML into String array lists. XPath was required for this, I also had to convert the elements into Strings and remove the extra tag information from the string using substrings since I only wanted the actual value.
I populated a JTable with these arrays.
Once users finished editing and clicked a save button then another Dom parser would take the original XML and change each and every attribute using the values from the Arrays (that were deleted and repopulated with the JTable cell values when the user clicked "save").
I use the docx4j for creating documents fed with XML data. The ContentControlBindingExtensions example shows how to use a simple for loop over the data to generate rows in invoice for each item from the XML file.
However, I can not find any way to repeat the whole page per each item (let's say my XML contains people and there should be one page per each person). When using the authoring add-in for Word (suggested here) I can't select the whole page to put the for loop on.
I thought I can insert a Page Break (Ctrl+Enter) at the end of the template and select it inside a for loop. However, this results in one empty line at the top of every page but the first.
You can put a hard page break (Word: Insert > Page Break) inside a rich text content control.
You can even put a Section Break inside a rich text content control, and this can be of type "Next Page".
So as long as your content is less than a page, you'll get a whole page per item.
I'm writing a Java test using cellenium, in order to validate the correctness of data I'm trying to extract the values of the table cells, although all cells have different values and meaning the <td> of all cells look the same and have the same attributes like so:
<td onclick="show_data('2','2','rowDetails.php','myID','434b2410aef9e61d6237dbbe562689a9b84','644');">2</td>
the naive solution would be to extract all tag <td> and then go by index.
Is there a better way?
If your elements have no unique identifier then the common way to solve your problem is by fetching all the TD elements and loop over them. This is something you already seem to be aware of, as you're describing this as: extract all tags and then go by index.
However, your provided example does contain a unique identifier, namely the property of the onclick attribute. By using CSS selectors, don't use XPath, you can do a select based on the property (the value) of the onclick attribute. This should help you to narrow down the elements you are looking for.
For list of CSS Selectors see: http://www.w3schools.com/cssref/css_selectors.asp
I have a question regarding how to access an index from a model attribute list dynamically.
In my code, I have some javascript which is reading a value from a model. The model has an attribute which is potentially a list.
document.getElementById("phoneNumberRPhone").value = "${model.people[index].phoneNumber.number}";
Here, you can see that I'm trying to set a javascript value to a number retrieved from a model where I can have multiple people. Index is my dynamic value. It works fine if I specifically state model.people[0] or model.people[1], but if I try to set a number to index and use index dynamically, it no longer works.
I would be very grateful for any help anyone could provide on this. I'm certain it's either just a matter of user error or improper use of syntax.
Apparently ${index} doesn't exist at all in the JSP/EL scope at the point JSP/EL has to print that piece of JS code. It would only work of you're doing for example (although this approach is highly questionable):
<c:forEach items="${model.people}" varStatus="loop">
document.getElementById("phoneNumberRPhone").value = "${model.people[loop.index].phoneNumber.number}";
</c:forEach>
Keep however in mind that JSP is merely a HTML code generator and that JavaScript is part of it. JSP and JavaScript doesn't run in sync. Rightclick page in webbrowser and do View Source to see it.
I want to list options in drop down menu in HTML form but i need to make some options to be multiline .and the options i need to read them from text file.any ideas how to do that?
In order to have your HTML display values from a text file, you're going to need to use some kind of server-side generation (ASP.NET, JSP, CGI, whatever). The exact solution will depend on what server-side technology you use/choose, but in all cases it should be fairly straightforward as this is a common requirement for all of these technologies.
As for your first part, what exactly do you mean by "some options to be multiline"? Do you mean that some values are quite long and have spaces, so you want them to wrap? Do you want to have some kind of drop-down box that shows multiple values at once? Do you want them not to be a dropdown at all? How will you decide between the values that should be multiline and those that should not? If you can express your intention more clearly (which may involve some additional thinking on your end), it will be possible to help, and you may even end up working out the solution yourself.