Struts2 dynamic form elements - struts2

I would like to create little higer-level framework on top of Struts2 which can take form element description from Action and render a complete form, in order to avoid having a separate JSP files with hardcoded form elements for every form in a large web application (so if I manage to do this I will have just a few generic JSPs for data form and few for layout). Application is extremely data-driven.
My idea is to create form description using custom objects in the Action (i.e. Button, TextInput etc.) and then to create a single JSP page that will render eveything out.
What is the best way of doing this? Can you propose some concrete way to do this?
I don't want to write something if I can reuse the existing code with some effort.
Any ideas are appreciated.
Kind regards,
Bozo

It seems to me you are trying to build a web framework on top of another, I doubt Struts2 is appropiate for that.
If you have a data-driven web app for which you dont want to write many similar JSP (or whatever view lang) pages, perhaps you'd better look at some frameworks with scaffolding abilities , eg Grails http://www.grails.org/Scaffolding

I did what I asked in the question myself - I have created a few generic JSP templates (list, edit etc.) which take application parameters and create output grids and forms using the struts2 and simple HTML tags. Using this method generic tiles definitions can also be created and used. So at the end using simple definition in the struts2 action, the grid and form is generated.

Related

Asp MVC reusable controls without using Editor Templates

I want to create a view that can be used twice on the same page, each time with a unique id.
At the moment I'm using two approaches to do this kind of thing
Editor Templates
stevensanderson's approach for having controls created on the fly
Editor Templates are the easiest as they take of the name mangling (e.g. parent1_parent2_childId) but Editor Templates can't be used across Areas and I really like Areas
Is there a 3rd option?
thanks
You can pass a model to a child view in the RenderPartial extension method. Use this mode to pass a desired id, or something from which it can be obtained.

asp.net mvc custom template for application forms and page

everyone, I'm really new with asp.net mvc
I have given this new task that converting existing application using asp.net webform into asp.net mvc
This application have basically have 3 type template form:
Grid Template (include the navigation such paging and search, and input/view form/panel shown after click, can be below or hide the grid)
Process Template (Grid with check box on each item to process)
Non-Grid Template (just input form, usually used for application parameter form)
This application also has some template pages, but basically this template page is combining just 1 template form or more (can be same template form), e.g parameter application form or sales order application (master and detail). The page can also has many detail show in tabs.
How do I achieve this templates using asp.net mvc as efficient as possible rather than just create new form and copy-paste from the other form.
I mean to minimalize the same code I have to write rather the specific thing that differentiate the form purpose, e.g the code just show the input form after click item.
Can anyone show me how I can do it or solution that came near to what I need?
Any link to tutorial, step by step, or anything?
Or if there any reasons I can't/shouldn't do it with asp.net mvc and what is the best way?
Thanks in advance and sorry if there are any mistakes in my words.
Editor/Display templates
They are mostly used for edit/display forms such as editing/displaying user profile data form, etc. Kind of like your Non-Grid Template. You can create Object templates, place them in the corresponding folders of the solution and they will be automatically every time you render your model via Html.EditorForModel() or Html.DisplayForModel helpers. Here is a good article to start with ASP.NET MVC 2 Templates, Part 4: Custom Object Templates
Shared views
I'm not sure what your Process template looks like but it seems it's a fixed number column grid like a one column with chackboxes and one more column with names of the items to process. In this case you'd better create an interface and a shared view. Then you can use the interface to map your view model to and render it with your shared view via Html.Partial helper.
Html helpers
For more advance grid templates just use a grid template, there are a lot of online, personelly I prefer Grid helper from MvcContrib library.
Two combine different templates within a single page use layout, sections and again shared view. Here is a good video about how to create and use them Asp Net MVC 4 - 02 Creating Layout, Views and Partial Views
Can't advice anything more specific as I don't really know what you WebForm application actually looks like but I think I described everything you need to start with.
Hope it helps!

ASP.NET MVC Aggregate CSS/JS from multiple controllers

We have a fairly complex application that was previously using WebForms. We are in the process of rewriting bits of it from scratch using MVC. Our application is comprised of a number of widgets, that together make up the functionality of the application.
In WebForms, we used UserControls. Each UserControl would register its CSS and JavaScript by means of a collection that was stored in HttpContext.Current.Items. That collection would then be merged to output as one single request. Typically this would occur in the Page_Load event, and the containing page would then render out a script tag that would comprise all the JavaScript and CSS needed for that page.
We've been struggling with doing the same in MVC. We are using a number of views within a masterpage to mimic the widgets. Each widget has its own controller, so the functionality can be sufficiently segregated. The masterpage builds up the widgets on the page using RenderAction from MVC futures. Originally we were using the same registration method for the CSS/JS files. Each controller would register its required files in an Action. The files would then be contained in the HttpContext.Current.Items collection, and would be rendered out to the page. To facilitate this, I wrote an HtmlHelper extension to render the links/scripts out to the page. It looks like this:
<%= Html.GetRegisteredCssFiles() %>
The problem is that MVC uses a more top down approach. This call is made in the tag of the page, but our subsequent calls to RenderAction happen below. By the time RenderAction is called and the required files are registered in HttpContext.Current.Items, the code above has already executed. So, the collection is not modified at the right time.
Does anyone have any ideas on how we should be constructing this? I'm looking for answers that incorporate best practices for MVC.
This question was asked a lot of time ago, so probably you've dealt with this already. But for future visitors, maybe this solution will be helpful:
http://marcinbudny.blogspot.com/2010/01/handling-stylesheet-references-in.html
The Free Telerik MVC tools have a script and a style register that might do what you want ...
Not sure if this is a feasible solution for you, but try moving that call to the bottom of each page.
I've always included my javascript and css files in the html HEAD, so I don't know if it would work lower down. My assumption is that it'll work in most browsers, but you might have random problems in a few.
The alternative is to have GetRegisteredFiles() output some javascript that loads the CSS files in the proper place (via DOM manipulation).
The problem with either of these solutions is that the files aren't included until the end, which could cause the page to look "plain" until the CSS is downloaded.
Alternatively, the controller could predict which "widgets" will get loaded and pass that data to the master page.

How to handle anchor tags properly consistently in ASP.NET MVC?

I am working on an fairly simple CRUD application in ASP.NET MVC. The rule for handling anchor tag inputs are fairly straight forward:
All text inputs contains anchor tags
are saved as-is in the database and
will be encoded as HTML entities when
rendering to the view.
Currently I am doing this one by one for each text field in the view .aspx page but I think there's gotta be a better way to do this in ASP.NET MVC. Can someone tell me how?
Could you inherit from the basic text field control (TextBox?) and customize that control, then use it wherever it's needed? I've seen lots of situations where developers create customized controls with validation controls added optionally.
Have you tried using a PartialView? That way you can re-use the same code again and again and simply change the parameters.
Or is that not what you're asking? if not then could you post some code?

Large data entry pages using ASP.NET MVC

I am working on a large data entry page using the default ASP.NET MVC theme. Due to the large number of controls on the page it would be good to use a two column fieldset so the user does not need to scroll. I can't see any templates in the MVC design gallery that use a two column data entry page, they are all geared towards standard website designs. Has anyone seen any? It would be great to have templates for different data entry scenarios.
Thanks
Danny
What you can do is create your own T4 (Text Template Transformation Toolkit) file. You can find out more here. This will give you an extra view content option in your "Add View" dialog box, generating the HTML however you've specified.
If your problem is to show all controls on single window without scrolling and may be using two columns,Right!
I have another solution for you.
And that is Wizard. check out this link and this link.
Your form will look nice!
If your issue is layout, you can lay it out in the design view first (or dreamweaver or the designer of your choice) then add the MVC specific code.

Resources